package com.heima.article.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.article.service.AuthorService;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/author")
@Api(value = "文章作者Controller",tags = "文章作者")
public class AuthorController {

    @Autowired
    AuthorService authorService;

    @ApiOperation("根据用户ApUserId 查询作者信息")
    @GetMapping("/findByUserId/{id}")
    public ResponseResult<ApAuthor> findByUserId(@PathVariable Integer id){
       //Apuser的id在作者信息中 存储的是userid 所以查询不能直接byid
        ApAuthor author = authorService.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getUserId, id));
        return ResponseResult.okResult(author);
    }

    @ApiOperation("保存作者信息")
    @PostMapping("/save")
    public ResponseResult<ApAuthor> saveApAuthor(@RequestBody ApAuthor apAuthor){
        authorService.save(apAuthor);
        return ResponseResult.okResult(apAuthor);
    }


}
